package com.epam.edu.command;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

public class CommandFactory {
    protected Map<String, Command> commandMap;

    public CommandFactory() {
        super();
    }

    public Command create(HttpServletRequest request) {
        if (commandMap == null) {
            defaultMap();
        }
        String action = request.getParameter("action");
        Command command = commandMap.get(action);
        return command;
    }

    protected Map defaultMap() {
        commandMap = new HashMap<String, Command>();

        commandMap.put("login", new LoginCommand());
        commandMap.put("signIn", new SignInCommand());
        commandMap.put("goto", new GoToPageCommand());
        commandMap.put("signOut", new SignOutCommand());
        commandMap.put("registration", new RegistrationCommand());
        commandMap.put("changePassword", new ChangePasswordCommand());
        commandMap.put("catalogSpecialties", new CatalogSpecialitiesCommand());
        commandMap.put("saveSpecialty", new SaveSpecialtyCommand());
        commandMap.put("newOrder", new OrdersFirstStepCommand());
        commandMap.put("saveInputMarks", new SaveInputMarksCommand());
        commandMap.put("orderSecondStep", new OrdersSecondStepCommand());
        commandMap.put("catalogAdmissions", new CatalogAdmissionsCommand());
        commandMap.put("saveAdmission", new SaveAdmissionsCommand());
        commandMap.put("orderFourthStep", new OrderFourthStepCommand());
        commandMap.put("orderThirdStep", new OrderThirdStepCommand());
        commandMap.put("inputMarksMenu", new InputMarksCommand());
        commandMap.put("ordersList", new OrderListCommand());
        commandMap.put("orderView", new OrderViewCommand());
        return commandMap;
    }
}
